package com.util;

import java.util.Random;

/**
 * Created by ke on 2015/10/10.
 */
public class DigitalUtil {
    public static int max(int a, int b, int c) {
        if (b > a) {
            a = b;
        }
        if (c > a) {
            a = c;
        }
        return a;
    }

    public static int max(int[] array) {
        int max = array[0];
        for (int j = 1; j < array.length; j++) {
            if (array[j] > max) {
                max = array[j];
            }
        }
        return max;
    }

    public static int min(int a, int b, int c) {
        if (b < a) {
            a = b;
        }
        if (c < a) {
            a = c;
        }
        return a;
    }

    public static int min(int[] array) {
        int min = array[0];
        for (int j = 1; j < array.length; j++) {
            if (array[j] < min) {
                min = array[j];
            }
        }
        return min;
    }

    public static int toInt(String intStr) {
        return Integer.parseInt(intStr);
    }

    public static int toInt(String intStr, int defaultValue) {
        if (intStr == null || intStr.length() == 0) {
            return defaultValue;
        }
        return toInt(intStr);
    }

    public static String toString(int value) {
        return String.valueOf(value);
    }

    public static String getRandomCharAndNumber(Integer length) {
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            boolean b = random.nextBoolean();
            if (b) { // 字符串
                // int choice = random.nextBoolean() ? 65 : 97; 取得65大写字母还是97小写字母
                sb.append((char) (65 + random.nextInt(26))); // 取得大写字母
            } else { // 数字
                sb.append(String.valueOf(random.nextInt(10)));
            }
        }
        return sb.toString();
    }

}
